package com.example.hangzhou.welbeing.mytestdemoapp.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.hangzhou.welbeing.mytestdemoapp.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 杭州惟君医疗科技有限公司09
 * Created by 20433 on 2018/5/15
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class MyProgressFragment extends Fragment {
    @Bind(R.id.fragment_my_progress_one_pgb_01)
    ProgressBar fragmentMyProgressOnePgb01;
    @Bind(R.id.fragment_my_progress_one_bt_01)
    Button fragmentMyProgressOneBt01;
    @Bind(R.id.fragment_my_progress_one_tv_01)
    TextView fragmentMyProgressOneTv01;
    @Bind(R.id.fragment_my_progress_one_pgb_02)
    ProgressBar fragmentMyProgressOnePgb02;
    @Bind(R.id.fragment_my_progress_one_tv_02)
    TextView fragmentMyProgressOneTv02;
    @Bind(R.id.fragment_my_progress_one_bt_02)
    Button fragmentMyProgressOneBt02;
    @Bind(R.id.fragment_my_progress_one_pgb_03)
    ProgressBar fragmentMyProgressOnePgb03;
    @Bind(R.id.fragment_my_progress_one_tv_03)
    TextView fragmentMyProgressOneTv03;
    @Bind(R.id.fragment_my_progress_one_bt_03)
    Button fragmentMyProgressOneBt03;
    @Bind(R.id.fragment_my_progress_one_pgb_04)
    ProgressBar fragmentMyProgressOnePgb04;

    @Bind(R.id.fragment_my_progress_one_bt_04)
    Button fragmentMyProgressOneBt04;
    @Bind(R.id.fragment_my_progress_one_pgb_05)
    ProgressBar fragmentMyProgressOnePgb05;

    @Bind(R.id.fragment_my_progress_one_bt_5)
    Button fragmentMyProgressOneBt5;
    @Bind(R.id.fragment_my_progress_one_pgb_06)
    ProgressBar fragmentMyProgressOnePgb06;
    @Bind(R.id.fragment_my_progress_one_bt_6)
    Button fragmentMyProgressOneBt6;
    private Context mcontext;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mcontext = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my_progress_one, container, false);
        ButterKnife.bind(this, view);
        init();
        return view;
    }

    private void init() {
        fragmentMyProgressOneTv01.setText("第一进度：" + fragmentMyProgressOnePgb01.getProgress() * 100.0 / fragmentMyProgressOnePgb01.getMax() + "%" +
                " 第二进度：" + fragmentMyProgressOnePgb01.getSecondaryProgress() * 100.0 / fragmentMyProgressOnePgb01.getMax() + "%");

        fragmentMyProgressOneTv02.setText("第一进度：" + fragmentMyProgressOnePgb02.getProgress() * 100.0 / fragmentMyProgressOnePgb02.getMax() + "%" +
                " 第二进度：" + fragmentMyProgressOnePgb02.getSecondaryProgress() * 100.0 / fragmentMyProgressOnePgb02.getMax() + "%");

        fragmentMyProgressOneTv03.setText("第一进度：" + fragmentMyProgressOnePgb03.getProgress() * 100.0 / fragmentMyProgressOnePgb03.getMax() + "%" +
                " 第二进度：" + fragmentMyProgressOnePgb03.getSecondaryProgress() * 100.0 / fragmentMyProgressOnePgb03.getMax() + "%");

        //设置进度条颜色
        fragmentMyProgressOnePgb05.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progressbar));
        fragmentMyProgressOnePgb04.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progressbar));
        fragmentMyProgressOnePgb06.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progressbar));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.fragment_my_progress_one_bt_01, R.id.fragment_my_progress_one_bt_02,
            R.id.fragment_my_progress_one_bt_03,R.id.fragment_my_progress_one_bt_04,
            R.id.fragment_my_progress_one_bt_5,R.id.fragment_my_progress_one_bt_6})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fragment_my_progress_one_bt_01:
                fragmentMyProgressOnePgb01.incrementProgressBy(10);
                fragmentMyProgressOnePgb01.setSecondaryProgress(fragmentMyProgressOnePgb01.getProgress() + 30);
                fragmentMyProgressOneTv01.setText("第一进度：" + fragmentMyProgressOnePgb01.getProgress() * 100.0 / fragmentMyProgressOnePgb01.getMax() + "%" +
                        " 第二进度：" + fragmentMyProgressOnePgb01.getSecondaryProgress() * 100.0 / fragmentMyProgressOnePgb01.getMax() + "%");
                break;
            case R.id.fragment_my_progress_one_bt_02:
                fragmentMyProgressOnePgb02.incrementProgressBy(10);
                fragmentMyProgressOnePgb02.setSecondaryProgress(fragmentMyProgressOnePgb02.getProgress() + 30);
                fragmentMyProgressOneTv02.setText("第一进度：" + fragmentMyProgressOnePgb02.getProgress() * 100.0 / fragmentMyProgressOnePgb02.getMax() + "%" +
                        " 第二进度：" + fragmentMyProgressOnePgb02.getSecondaryProgress() * 100.0 / fragmentMyProgressOnePgb02.getMax() + "%");
                break;
            case R.id.fragment_my_progress_one_bt_03:
                fragmentMyProgressOnePgb03.incrementProgressBy(10);
                fragmentMyProgressOnePgb03.setSecondaryProgress(fragmentMyProgressOnePgb03.getProgress() + 30);
                fragmentMyProgressOneTv03.setText("第一进度：" + fragmentMyProgressOnePgb03.getProgress() * 100.0 / fragmentMyProgressOnePgb03.getMax() + "%" +
                        " 第二进度：" + fragmentMyProgressOnePgb03.getSecondaryProgress() * 100.0 / fragmentMyProgressOnePgb03.getMax() + "%");
                break;
            case R.id.fragment_my_progress_one_bt_04:   //设置进度条颜色

                break;
            case R.id.fragment_my_progress_one_bt_5:

                break;
            case R.id.fragment_my_progress_one_bt_6:
                break;
        }
    }

}
